<style>
  .ivu-input[disabled], fieldset[disabled] .ivu-input {
    background-color: white;
    opacity: 1;
    cursor: not-allowed;
    color: #515A6E;
  }
  .ivu-select-disabled .ivu-select-selection {
    background-color: white;
    opacity: 1;
    cursor: not-allowed;
    color: #515A6E;
  }
  .ivu-select-input[disabled] {
    cursor: not-allowed;
    color: #515A6E;
    -webkit-text-fill-color: #515A6E;
}
</style>
<template>
    <div class="form-block-inner">
      <Form :model="formInfo" label-position="top" :disabled="!editFlag" :rules="ruleValidate" ref="addBaseForm">
        <div class="title-style">采集点基本信息</div>
        <Row :gutter="16">
          <Col span="5">
            <FormItem label="采集点编号：" prop="place_code" :disabled="true">
              <Input type="text" v-model="formInfo.place_code" placeholder="请输入采集点编号"/>
            </FormItem>
          </Col>
          <Col span="5">
            <FormItem label="采集点名称：" prop="place_name">
              <Input type="text" v-model="formInfo.place_name" placeholder="请输入采集点名称"/>
            </FormItem>
          </Col>
          <Col span="5">
            <FormItem label="采集点负责人：" prop="place_person">
              <Input type="text" v-model="formInfo.place_person" placeholder="请输入采集点负责人"/>
            </FormItem>
          </Col>
          <!-- <Col span="5">
            <FormItem>
              <template slot="label">
                <span class="red-star">*</span>采集点名称：
              </template>
              <RadioGroup v-model="formInfo.sex">
                <Radio label="男">男</Radio>
                <Radio label="女">女</Radio>
              </RadioGroup>
            </FormItem>
          </Col> -->
          <Col span="5">
            <FormItem>
              <template slot="label">
                <span class="red-star">*</span>采集点类型：
              </template>
              <Select v-model="formInfo.place_type" placeholder="采集点负责人" filterable>
                <Option value="0">区属</Option>
                <Option value="1">市属</Option>
              </Select>
              <!-- <Select v-model="formInfo.card_type" placeholder="请选择证件类型"
                      @on-change="ruleValidate.card_no[0].card_type=formInfo.card_type">
                <Option value="1">身份证</Option>
                <Option value="2">军官证</Option>
                <Option value="3">护照</Option>
                <Option value="4">港澳通行证</Option>
              </Select> -->
            </FormItem>
          </Col>
        </Row>
        <Row :gutter="16">
          <Col span="5" v-show="formInfo.place_type == '0'">
            <FormItem label="区属编码：" prop="place_type_code">
              <Select v-model="formInfo.place_type_code" placeholder="请选择区属编码" filterable>
                <Option v-for="obj in quArr" :value="obj.code" :key="obj.code">{{obj.name}}</Option>
              </Select>
              <!-- <Input type="text" v-model="formInfo.place_type_code" placeholder="请输入区属编码"/> -->
            </FormItem>
          </Col>
          <Col span="5">
            <FormItem label="采集点地址：" prop="place_address">
              <Input type="text" v-model="formInfo.place_address" placeholder="请输入采集点地址"/>
            </FormItem>
          </Col>
          <Col span="5">
            <FormItem label="采集点类型2：" prop="place_type2">
              <Select v-model="formInfo.place_type2" placeholder="请选择采集点类型2" filterable>
                <Option value="0">社区</Option>
                <Option value="1">学校</Option>
                <Option value="2">其他第三方机构</Option>
              </Select>
            </FormItem>
          </Col>
          <Col span="5">
            <FormItem label="创建时间：" prop="create_time">
              <Input type="text" v-model="formInfo.create_time"/>
            </FormItem>
          </Col>
          <Col span="5">
            <FormItem label="创建账号：" prop="create_by">
              <Input type="text" v-model="formInfo.create_by"/>
            </FormItem>
          </Col>
        </Row>
        <div>
          <div class="title-style">
            <span>人员情况</span>
            <Button class="add-btn" size="small" type="info" @click="editRow({}, '1', '人员情况')"
                    shape="circle" icon="md-add"></Button>
          </div>
          <Table :loading="relevantPerson.partnerLoading" border :columns="columnsPerson"
                :data="relevantPerson.partnerList" size="small">
            <template slot="action" slot-scope="{ row }">
              <Button type="success" class="table-mr5" size="small" @click="editRow(row, '1', '人员情况')">编辑</Button>
              <Button type="error" size="small" @click="deleteRow(row, '1')">删除</Button>
            </template>
          </Table>
          <Row type="flex" justify="end" class="page_style">
            <Page :current="currentPageNo" :total="totalnum" :page-size="currentPageSize"
                  show-total @on-change="changePageNo"/>
          </Row>
          <div class="title-style">
            <span>车辆情况</span>
            <Button class="add-btn" size="small" type="info" @click="editRow1({}, '2', '车辆情况')"
                    shape="circle" icon="md-add"></Button>
          </div>
          <Table :loading="relevantPerson.contactLoading" border :columns="columns1"
                :data="relevantPerson.contactList" size="small">
            <template slot="action" slot-scope="{ row }">
              <Button type="success" class="table-mr5" size="small" @click="editRow1(row, '2', '车辆情况')">编辑</Button>
              <Button type="error" size="small" @click="deleteRow1(row, '2')">删除</Button>
            </template>
          </Table>
          <Row type="flex" justify="end" class="page_style">
            <Page :current="currentPageNo1" :total="totalnum1" :page-size="currentPageSize1"
                  show-total @on-change="changePageNo1"/>
          </Row>
          <div class="title-style">
            <span>物资情况</span>
          </div>
          <Table :loading="relevantPerson.materialLoading" border :columns="columns2"
                :data="tempArr" size="small">
            <template slot-scope="{ row }" slot="hsjcsjh">
              <span v-if="!row.update">{{row.hsjcsjh}}</span>
              <Input type="number" v-else v-model="row.hsjcsjh"></Input>
            </template>
            <template slot-scope="{ row }" slot="hstqsjh">
              <span v-if="!row.update">{{row.hstqsjh}}</span>
              <Input type="number" v-else v-model="row.hstqsjh"></Input>
            </template>
            <template slot-scope="{ row }" slot="xqzdsjh">
              <span v-if="!row.update">{{row.xqzdsjh}}</span>
              <Input type="number" v-else v-model="row.xqzdsjh"></Input>
            </template>
            <template slot-scope="{ row }" slot="swaqzyx">
              <span v-if="!row.update">{{row.swaqzyx}}</span>
              <Input type="number" v-else v-model="row.swaqzyx"></Input>
            </template>
            <template slot-scope="{ row }" slot="zwaqzyp">
              <span v-if="!row.update">{{row.zwaqzyp}}</span>
              <Input type="number" v-else v-model="row.zwaqzyp"></Input>
            </template>
            <template slot-scope="{ row }" slot="bdcyg">
              <span v-if="!row.update">{{row.bdcyg}}</span>
              <Input type="number" v-else v-model="row.bdcyg"></Input>
            </template>
            <template slot-scope="{ row }" slot="n95kz">
              <span v-if="!row.update">{{row.n95kz}}</span>
              <Input type="number" v-else v-model="row.n95kz"></Input>
            </template>
            <template slot-scope="{ row }" slot="fhf">
              <span v-if="!row.update">{{row.fhf}}</span>
              <Input type="number" v-else v-model="row.fhf"></Input>
            </template>
            <template slot-scope="{ row }" slot="yjcyb">
              <span v-if="!row.update">{{row.yjcyb}}</span>
              <Input type="number" v-else v-model="row.yjcyb"></Input>
            </template>
            <template slot-scope="{ row }" slot="rypbll">
              <span v-if="!row.update">{{row.rypbll}}</span>
              <Input type="number" v-else v-model="row.rypbll"></Input>
            </template>
            <template slot="action" slot-scope="{ row, index }">
              <Button type="primary" class="mr5" size="small" v-show="!row.update" style="margin-right:5px" @click="saveInfo(row,index)">修改</Button>
              <Button type="primary" class="mr5" size="small" v-show="row.update" style="margin-right:5px" @click="confirmWp(row,index)">确认</Button>
              <!-- <Button type="success" class="table-mr5" size="small" @click="editRow1(row)">编辑</Button> -->
            </template>
          </Table>
        </div>

        <Row type="flex" justify="center" :gutter="16">
          <Col span="3" v-if="editFlag">
            <Button type="primary" :loading="saving" class="save-btn mr20" long @click="saveAllInfo">保 存</Button>
          </Col>
          <Col span="3">
            <Button type="error" class="save-btn" long @click="back">返 回</Button>
          </Col>
        </Row>

        <Modal v-model="modalInfo.show" :title="modalInfo.title" width="700">
          <Form label-position="right">
            <Row class="bench_search">
              <Col span="7" class="ivu-form-item-label">采集点编号：</Col>
              <Col span="12" class="ivu-form-item-content">
                <Input type="text" v-model="modalInfo.place_code" placeholder="采集点名称"></Input>
              </Col>
            </Row>
            <Row class="bench_search">
              <Col span="7" class="ivu-form-item-label">姓名：</Col>
              <Col span="12" class="ivu-form-item-content">
                <Input type="text" v-model="modalInfo.person_name" placeholder="姓名"></Input>
              </Col>
            </Row>
            <Row class="bench_search">
              <Col span="7" class="ivu-form-item-label">证件编号：</Col>
              <Col span="12" class="ivu-form-item-content">
                <Input type="text" v-model="modalInfo.person_card_no" placeholder="证件编号"></Input>
              </Col>
            </Row>
            <Row class="bench_search">
              <Col span="7" class="ivu-form-item-label">手机号码：</Col>
              <Col span="12" class="ivu-form-item-content">
                <Input type="text" v-model="modalInfo.person_mobile" placeholder="手机号"></Input>
              </Col>
            </Row>
            <Row class="bench_search">
              <Col span="7" class="ivu-form-item-label">人员类型：</Col>
              <Col span="12" class="ivu-form-item-content">
                <Select v-model="modalInfo.person_type" placeholder="请选择人员类型" filterable>
                  <Option value="0">负责人</Option>
                  <Option value="1">医护人员</Option>
                  <Option value="2">公安干警</Option>
                  <Option value="3">社区干部</Option>
                </Select>
              </Col>
            </Row>
          </Form>
          <div slot="footer">
            <Button type="success" @click="saveModalInfo">确定</Button>
            <Button type="error" @click="modalInfo.show=false">关闭</Button>
          </div>
        </Modal>
        <Modal v-model="modalInfo1.show" :title="modalInfo1.title" width="700">
          <Form label-position="right">
            <Row class="bench_search">
              <Col span="7" class="ivu-form-item-label">采集点编号：</Col>
              <Col span="12" class="ivu-form-item-content">
                <Input type="text" v-model="modalInfo1.place_code" placeholder="采集点名称"></Input>
              </Col>
            </Row>
            <Row class="bench_search">
              <Col span="7" class="ivu-form-item-label">车牌号：</Col>
              <Col span="12" class="ivu-form-item-content">
                <Input type="text" v-model="modalInfo1.car_no" placeholder="姓名"></Input>
              </Col>
            </Row>
            <Row class="bench_search">
              <Col span="7" class="ivu-form-item-label">车辆品牌型号：</Col>
              <Col span="12" class="ivu-form-item-content">
                <Input type="text" v-model="modalInfo1.car_name" placeholder="证件编号"></Input>
              </Col>
            </Row>
            <Row class="bench_search">
              <Col span="7" class="ivu-form-item-label">司机姓名：</Col>
              <Col span="12" class="ivu-form-item-content">
                <Input type="text" v-model="modalInfo1.person_name" placeholder="司机姓名"></Input>
              </Col>
            </Row>
            <Row class="bench_search">
              <Col span="7" class="ivu-form-item-label">司机身份证号码：</Col>
              <Col span="12" class="ivu-form-item-content">
                <Input type="text" v-model="modalInfo1.person_card_no" placeholder="手机号"></Input>
              </Col>
            </Row>
            <Row class="bench_search">
              <Col span="7" class="ivu-form-item-label">司机手机号：</Col>
              <Col span="12" class="ivu-form-item-content">
                <Input type="text" v-model="modalInfo1.person_mobile" placeholder="手机号"></Input>
              </Col>
            </Row>
          </Form>
          <div slot="footer">
            <Button type="success" @click="saveModalInfo1">确定</Button>
            <Button type="error" @click="modalInfo1.show=false">关闭</Button>
          </div>
        </Modal>
      </Form>
    </div>
</template>

<script>
import { getQuList, updatePlaceCJByCode, insertPlaceCJPersion, updatePlaceCJPersionById, getPlaceCJPersonList, deletePlaceCjPersonById, insertPlaceCJCar, updatePlaceCJCarById, getPlaceCJCarList, deletePlaceCjCarById, updatePlaceCJWPByCode, getPlaceCJWP, getPlaceCJ } from '@/api/nucleic-acid-detection'
import validateData from './validate'
// import { grid_downlist, date2str } from '@/api/eventlist'
import { getSign, createUpLoadFiles, getCityList } from '@/api/common'
import { createuserinfo, updateuserinfo, getuserinfo, getuserinfoApp, getDictList } from '@/api/yi-qing-fang-kong'

export default {
  name: 'add',
  data () {
    return {
      tempArr: [],
      currentPageNo: 1,
      currentPageSize: 10,
      totalnum: 0,
      currentPageNo1: 1,
      currentPageSize1: 10,
      totalnum1: 0,
      place_code: this.$route.query.place_code,
      quArr: [],
      fromApp: false,
      editFlag: true,
      addFlag: true,
      saving: false,
      company_type: '1',
      ruleValidate: validateData.ruleValidate,
      occupationList: validateData.formData.occupationList,
      focusPlaceList: validateData.formData.focusPlaceList,
      formInfo: {},
      addressInfo: { list1: [], list2: [], list3: [] },
      inoutCity: { provinceList: [], city1: [], city2: [] },
      columnsPerson: [
        { title: '序号', type: 'index', width: 80, align: 'center' },
        { title: '姓名', key: 'person_name', width: 150 },
        { title: '证件号码', key: 'person_card_no', width: 200 },
        { title: '联系方式', key: 'person_mobile', width: 200 },
        { title: '人员类型', key: 'person_type' },
        { title: '操作', align: 'center', width: 200, slot: 'action' }
      ],
      columns1: [ // 车辆列表
        { title: '序号', type: 'index', width: 60, align: 'center' },
        { title: '司机身份证号码', key: 'person_card_no', width: 200, align: 'center' },
        { title: '司机姓名', key: 'person_name', align: 'center' },
        { title: '司机手机号', key: 'person_mobile', align: 'center' },
        { title: '创建时间', key: 'create_time', align: 'center' },
        { title: '创建账号', key: 'create_by', align: 'center' },
        { title: '操作', align: 'center', width: 200, slot: 'action' }
      ],
      columns2: [ // 物品列表
        { title: '核酸检测试剂盒', slot: 'hsjcsjh', align: 'center' },
        { title: '核酸提取试剂盒', slot: 'hstqsjh', align: 'center' },
        { title: '血清诊断试剂盒', slot: 'xqzdsjh', align: 'center' },
        { title: '生物安全转运箱', slot: 'swaqzyx', align: 'center' },
        { title: '生物安全转云盘', slot: 'zwaqzyp', align: 'center' },
        { title: '病毒采样管', slot: 'bdcyg', align: 'center' },
        { title: 'N95口罩', align: 'center', slot: 'n95kz' },
        { title: '防护服', slot: 'fhf', align: 'center' },
        { title: '应急采样包', slot: 'yjcyb', align: 'center' },
        { title: '人员配备力量', align: 'center', slot: 'rypbll' },
        { title: '操作', align: 'center', width: 200, slot: 'action' }
      ],
      relevantPerson: {
        partnerLoading: false,
        contactLoading: false,
        partnerList: [],
        contactList: [],
        materialLoading: false,
        materialList: []
      },
      modalInfo: { show: false },
      modalInfo1: { show: false },
      temp_photo: '',
      uploadModShow: false,
      stateList: [],
      arriveAddressTypeList: [],
      superviseTypeList: [],
      helpTipList: [
        '2020年1月开始的常住起居地城市',
        '火车列次号、飞机航班号、客车出发地及时间、自驾出发时间途径地等等',
        '原起居地址（观察地），在沈期间常住地址'
      ]
    }
  },
  watch: {
    // $route: function (to, from) {
    //   this.company_type = to.query.user_type
    //   this.formInfo.state = to.query.state || '1'
    //   if (to.query.state === '4') {
    //     this.stateList = validateData.formData.curStateList[1]
    //   } else {
    //     this.stateList = validateData.formData.curStateList[0]
    //   }
    // }
  },
  methods: {
    saveAllInfo () { // 采集点基本信息修改
      this.$refs.addBaseForm.validate((valid) => {
        if (valid) {
          let param = {
            place_code: this.$route.query.place_code,
            place_name: this.formInfo.place_name,
            place_person: this.formInfo.place_person,
            place_type: this.formInfo.place_type,
            place_type_code: this.formInfo.place_type_code,
            place_address: this.formInfo.place_address,
            place_type2: this.formInfo.place_type2
          }
          console.log(param, 'param')
          updatePlaceCJByCode(param).then(res => {
            if (res.data.errcode === 0) {
              this.$Notice.success({ title: '修改成功' })
            } else {
              this.$Notice.error({ title: '添加失败', desc: res.data.errmsg })
            }
            this.saving = false
          })
        } else {
          this.saving = false
          this.$Notice.warning({ title: '请查看表必填项!' })
        }
      })
    },
    editRow (row, type, title) {
      this.modalInfo.title = title
      this.modalInfo.place_code = this.$route.query.place_code
      if (row) {
        this.modalInfo.id = row.id
        this.modalInfo.person_name = row.person_name
        this.modalInfo.person_card_no = row.person_card_no
        this.modalInfo.person_mobile = row.person_mobile
        this.modalInfo.person_type = row.person_type
      }
      this.modalInfo.show = true
    },
    editRow1 (row, type, title) {
      this.modalInfo1.title = title
      this.modalInfo1.place_code = this.$route.query.place_code
      if (row) {
        this.modalInfo1.id = row.id
        this.modalInfo1.car_no = row.car_no
        this.modalInfo1.car_name = row.car_name
        this.modalInfo1.person_name = row.person_name
        this.modalInfo1.person_card_no = row.person_card_no
        this.modalInfo1.person_mobile = row.person_mobile
      }
      this.modalInfo1.show = true
    },
    deleteRow (row, type) {
      this.$Modal.confirm({
        title: '删除后无法找回，确认操作！',
        onOk: () => {
          deletePlaceCjPersonById({ id: row.id }).then(res => {
            if (res.data.data) {
              this.$Notice.success({ title: '删除成功' })
              this.getPersonList('', 1)
            } else {
              this.$Notice.error({ title: '删除失败' })
            }
          })
        }
      })
    },
    deleteRow1 (row, type) {
      this.$Modal.confirm({
        title: '删除后无法找回，确认操作！',
        onOk: () => {
          deletePlaceCjCarById({ id: row.id }).then(res => {
            if (res.data.data) {
              this.$Notice.success({ title: '删除成功' })
              this.getVehicleList('', 1)
            } else {
              this.$Notice.error({ title: '删除失败' })
            }
          })
        }
      })
    },
    saveModalInfo () {
      if (!this.modalInfo.person_name) {
        this.$Notice.warning({ title: '错误', desc: '请填写姓名' })
        return
      }
      if (!this.modalInfo.person_card_no) {
        this.$Notice.warning({ title: '错误', desc: '请填写证件编号' })
        return
      }
      if (!this.modalInfo.person_mobile) {
        this.$Notice.warning({ title: '错误', desc: '请填写手机号码' })
        return
      }
      if (!this.modalInfo.person_type) {
        this.$Notice.warning({ title: '错误', desc: '请选择人员类型' })
        return
      }
      let param = {
        id: this.modalInfo.id,
        place_code: this.modalInfo.place_code,
        person_card_no: this.modalInfo.person_card_no,
        person_name: this.modalInfo.person_name,
        person_mobile: this.modalInfo.person_mobile,
        person_type: this.modalInfo.person_type
      }
      if (param.id) {
        updatePlaceCJPersionById(param).then(res => {
          if (res.data.data) {
            this.modalInfo.show = false
            this.getPersonList('', 1)
            this.$Notice.success({ title: '修改成功' })
          } else {
            this.$Notice.error({ title: '修改失败' })
          }
        })
      } else {
        insertPlaceCJPersion(param).then(res => {
          if (res.data.data) {
            this.modalInfo.show = false
            this.$Notice.success({ title: '添加成功' })
            this.getPersonList('', 1)
          } else {
            this.$Notice.error({ title: '添加失败' })
          }
        })
      }
    },
    cancelModalInfo () {
      console.log('!@#@!#!#!#!#')
      this.modalInfo.show = false
    },
    saveModalInfo1 () {
      if (!this.modalInfo1.person_name) {
        this.$Notice.warning({ title: '错误', desc: '请填写司机姓名' })
        return
      }
      if (!this.modalInfo1.person_card_no) {
        this.$Notice.warning({ title: '错误', desc: '请填写证件编号' })
        return
      }
      if (!this.modalInfo1.person_mobile) {
        this.$Notice.warning({ title: '错误', desc: '请填写手机号码' })
        return
      }
      if (!this.modalInfo1.car_name) {
        this.$Notice.warning({ title: '错误', desc: '请填写车辆型号' })
        return
      }
      if (!this.modalInfo1.car_no) {
        this.$Notice.warning({ title: '错误', desc: '请填写车牌号' })
        return
      }
      let param = {
        id: this.modalInfo1.id,
        place_code: this.modalInfo1.place_code,
        person_card_no: this.modalInfo1.person_card_no,
        person_mobile: this.modalInfo1.person_mobile,
        person_name: this.modalInfo1.person_name,
        car_name: this.modalInfo1.car_name,
        car_no: this.modalInfo1.car_no
      }
      if (param.id) {
        updatePlaceCJCarById(param).then(res => {
          if (res.data.data) {
            this.modalInfo1.show = false
            this.$Notice.success({ title: '修改成功' })
            this.getVehicleList('', 1)
          } else {
            this.$Notice.error({ title: '修改失败' })
          }
        })
      } else {
        insertPlaceCJCar(param).then(res => {
          if (res.data.data) {
            this.modalInfo1.show = false
            this.$Notice.success({ title: '添加成功' })
            this.getVehicleList('', 1)
          } else {
            this.$Notice.error({ title: '添加失败' })
          }
        })
      }
    },
    saveInfo (row, index) {
      row.update = !row.update
      this.tempArr[index] = row
      // this.tempArr[index]['problems_id'] = row.id
    },
    confirmWp (row, index) { // 修改物品
      updatePlaceCJWPByCode(row).then(res => {
        if (res.data.errcode === 0) {
          this.$Notice.success({ title: '修改成功' })
          row.update = !row.update
        } else {
          this.$Notice.error({ title: '添加失败', desc: res.data.errmsg })
        }
        this.saving = false
      })
    },
    getuser (id) {
      let tempaaa = getuserinfo
      if (this.fromApp) {
        tempaaa = getuserinfoApp
      }
      tempaaa(id).then(res => {
        if (res.data.data) {
          this.formInfo = res.data.data
          this.formInfo.area1 = res.data.data.area
          this.formInfo.area2 = res.data.data.street
          this.formInfo.area3 = res.data.data.community
          this.formInfo.area5 = res.data.data.community
          this.formInfo.province1 = res.data.data.originate_province
          this.formInfo.province2 = res.data.data.out_province
          this.formInfo.city1 = res.data.data.originate_city
          this.formInfo.city2 = res.data.data.out_city
          this.formInfo.nucleic_acid = this.formInfo.nucleic_acid || '0'
          this.ruleValidate.card_no[0].card_type = this.formInfo.card_type
          this.getCity(null, 'provinceList', true)
          this.getDownAddress(0, 1, true)
        } else {
          this.$Notice.error({ title: '查询失败' })
        }
      })
    },
    createuser (param) {
      createuserinfo(param).then(res => {
        if (res.data.errcode === 0) {
          this.$Notice.success({ title: '添加成功' })
          this.formInfo.id = res.data.data.id
          this.addFlag = false
          this.$router.go(-1)
        } else {
          this.$Notice.error({ title: '添加失败', desc: res.data.errmsg })
        }
        this.saving = false
      })
    },
    updateuser (param) {
      updateuserinfo(param).then(res => {
        if (res.data.errcode === 0) {
          this.addFlag = false
          this.$Notice.success({ title: '修改成功' })
          this.$router.go(-1)
        } else {
          this.$Notice.error({ title: '修改失败', desc: res.data.errmsg })
        }
        this.saving = false
      })
    },
    banduser (user_id, type, loading) {
      let param = {
        type: type,
        user_id: user_id,
        pageNo: 1,
        pageSize: 200
      }
      let tempstr = type + ''
      tempstr = tempstr === '1' ? 'partner' : 'contact'
      this.relevantPerson[tempstr + 'Loading'] = true
      banduserlist(param).then(res => {
        if (res.data.data) {
          this.relevantPerson[tempstr + 'List'] = res.data.data.results
          this.relevantPerson[tempstr + 'Loading'] = false
        } else {
          this.$Notice.error({ title: '查询人员列表失败' })
          this.relevantPerson[tempstr + 'Loading'] = false
        }
      })
    },
    back () {
      this.$router.go(-1)
    },
    chaneProv (index) {
      let temparea = this.formInfo['province' + index]
      if (!temparea) {
        return
      }
      let templist = this.inoutCity.provinceList
      let tempdata = {}
      for (let i = 0; i < templist.length; i++) {
        if (temparea === templist[i].name) {
          tempdata = templist[i]
          break
        }
      }
      this.getCity(tempdata.code, 'city' + index, false)
    },
    getCity (code, listname, flag) {
      getCityList({ code: code }).then(res => {
        if (res.data.errcode === 0) {
          this.inoutCity[listname] = res.data.data
          if (flag) {
            if (this.formInfo.province1) {
              this.chaneProv(1)
            }
            if (this.formInfo.province2) {
              this.chaneProv(2)
            }
          }
        } else {
          this.$Notice.error({ title: '查询失败' })
        }
      })
    },
    showHelp (index) {
      let tip = this.helpTipList[index - 1] || '暂无提示信息'
      this.$Modal.info({ title: '提示信息', content: tip, okText: '知道了！' })
    },
    // 上传图片前转base64
    beforeUpload (file) {
      let upPicData = {
        filePath: 'itemorder/yiqing/' + this.formInfo.id,
        fileName: file.name
      }
      const reader = new FileReader()
      reader.readAsDataURL(file)
      reader.onload = () => {
        let index = reader.result.indexOf('base64,') + 7
        upPicData.file = reader.result.substring(index)
        this.upPic(upPicData)
      }
      return false
    },
    // 上传图片
    upPic (obj) {
      let timeStep = new Date().getTime().toString()
      let param = {
        filePath: obj.filePath,
        fileName: obj.fileName,
        timestamp: timeStep
      }
      getSign(param).then(res => {
        if (res.data.errcode === 0) {
          let uploadParam = {
            sign: res.data.data.sign,
            timestamp: timeStep,
            filePath: obj.filePath,
            fileName: obj.fileName,
            file: obj.file
          }
          createUpLoadFiles(res.data.data.docking_url, uploadParam).then(res => {
            if (res.data.errcode === 0) {
              this.temp_photo = res.data.data
              this.$Notice.success({ title: '上传成功' })
            } else {
              this.$Notice.error({ title: '上传失败', desc: res.data.data.msg })
            }
          })
        } else {
          this.$Notice.error({ title: '上传失败', desc: res.data.data.msg })
        }
      })
    },
    arriveTypeList () {
      this.arriveAddressTypeList = []
      this.superviseTypeList = []
      let param = {
        pageNo: 1,
        pageSize: 30,
        type: 'arrive_address_type'
      }
      let param1 = {
        pageNo: 1,
        pageSize: 30,
        type: 'supervise_start'
      }
      getDictList(param).then(res => {
        if (res.data.errcode === 0) {
          this.arriveAddressTypeList = res.data.data.results
        } else {
          this.$Notice.error({ title: '查询失败' })
        }
      })
      getDictList(param1).then(res => {
        if (res.data.errcode === 0) {
          let List = res.data.data.results
          List.forEach((item, index) => {
            console.log(item.value, item.label)
            if (item.value === '7') {
              List.splice(index, 1)
            }
          })
          List.forEach((item, index) => {
            console.log(item.value, item.label)
            if (item.value === '5') {
              List.splice(index, 1)
              this.superviseTypeList = List
            } else {
              this.superviseTypeList = List
            }
          })
        } else {
          this.$Notice.error({ title: '查询失败' })
        }
      })
    },
    getQuCodeList () { // 获取区列表
      getQuList({}).then(res => {
        if (res.data.errcode === 0) {
          this.quArr = res.data.data
        } else {
          this.$Notice.error({
            title: '获取区列表失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    getCjInfo () { // 获取采集点详情
      getPlaceCJ({ place_code: this.$route.query.place_code }).then(res => {
        if (res.data.errcode === 0) {
          this.formInfo = res.data.data
          // this.quArr = res.data.data
        } else {
          this.$Notice.error({
            title: '获取区列表失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    getPersonList (place_code, pageNo) { // 获取人员列表
      let param = {
        place_code: this.$route.query.place_code,
        pageNo: pageNo,
        pageSize: 10
      }
      getPlaceCJPersonList(param).then(res => {
        if (res.data.errcode === 0) {
          this.relevantPerson.partnerList = res.data.data.results
          this.totalnum = res.data.data.totalRecord
          for (var i = 0; i < this.relevantPerson.partnerList.length; i++) {
            if (this.relevantPerson.partnerList[i].person_type === '0') {
              this.relevantPerson.partnerList[i].person_type = '负责人'
            } else if (this.relevantPerson.partnerList[i].person_type === '1') {
              this.relevantPerson.partnerList[i].person_type = '医护人员'
            } else if (this.relevantPerson.partnerList[i].person_type === '2') {
              this.relevantPerson.partnerList[i].person_type = '公安干警'
            } else if (this.relevantPerson.partnerList[i].person_type === '3') {
              this.relevantPerson.partnerList[i].person_type = '社区干部'
            }
          }
          console.log(this.data2, '明细列表')
        } else {
          this.$Notice.error({
            title: '获取人员列表失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    changePageNo (pageNo) {
      console.log(pageNo, '页数')
      this.currentPageNo = pageNo
      this.params.pageNo = pageNo
      this.getPersonList(this.params)
    },
    getVehicleList (place_code, pageNo) { // 获取车辆列表
      let param = {
        place_code: this.$route.query.place_code,
        pageNo: pageNo,
        pageSize: 10
      }
      getPlaceCJCarList(param).then(res => {
        if (res.data.errcode === 0) {
          this.relevantPerson.contactList = res.data.data.results
          this.totalnum1 = res.data.data.totalRecord
          console.log(this.relevantPerson.contactList, '车辆列表')
        } else {
          this.$Notice.error({
            title: '获取车辆列表失败',
            desc: res.data.errmsg
          })
        }
      })
    },
    changePageNo1 (pageNo) { // 预约人员列表页码切换
      console.log(pageNo, '页数')
      this.currentPageNo1 = pageNo
      this.params1.pageNo = pageNo
      this.getVehicleList('', pageNo)
    },
    getMaterialList (place_code, pageNo) { // 获取车辆列表
      let param = {
        place_code: this.$route.query.place_code,
        pageNo: pageNo,
        pageSize: 10
      }
      getPlaceCJWP(param).then(res => {
        if (res.data.errcode === 0) {
          var obj = {
            bdcyg: res.data.data.bdcyg,
            fhf: res.data.data.fhf,
            hsjcsjh: res.data.data.hsjcsjh,
            hstqsjh: res.data.data.hstqsjh,
            n95kz: res.data.data.n95kz,
            rypbll: res.data.data.rypbll,
            place_code: res.data.data.place_code,
            swaqzyx: res.data.data.swaqzyx,
            xqzdsjh: res.data.data.xqzdsjh,
            yjcyb: res.data.data.yjcyb,
            zwaqzyp: res.data.data.zwaqzyp
          }
          this.tempArr.push(obj)
          if (this.tempArr.length > 0) {
            for (var i = 0; i < this.tempArr.length; i++) {
              this.tempArr[i].update = false
            }
          }
          console.log(this.tempArr, '物品列表')
        } else {
          this.$Notice.error({
            title: '获取物品列表失败',
            desc: res.data.errmsg
          })
        }
      })
    }
  },
  mounted () {
    this.modalInfo.place_code = this.$route.query.place_code
    this.modalInfo1.place_code = this.$route.query.place_code
    this.getQuCodeList()
    this.getCjInfo()
    this.getPersonList('place_code', 1)
    this.getVehicleList('place_code', 1)
    this.getMaterialList('place_code', 1)
    let queryData = this.$route.query || {}
    this.company_type = queryData.user_type || '1'
    this.fromApp = queryData.app === '1'
    if (queryData.state === '4') {
      this.stateList = validateData.formData.curStateList[1]
    } else {
      this.stateList = validateData.formData.curStateList[0]
    }
    this.arriveTypeList()
    // edit：修改，info：查看，add：添加(其他值算添加)
    if (queryData.what === 'edit') {
      this.editFlag = true
      this.addFlag = false
      this.getuser(queryData.id)
      this.banduser(queryData.id, 1)
      this.banduser(queryData.id, 2)
    } else if (queryData.what === 'info') {
      this.editFlag = false
      this.addFlag = false
      this.getuser(queryData.id)
      this.banduser(queryData.id, 1)
      this.banduser(queryData.id, 2)
    } else {
      this.editFlag = true
      this.addFlag = true
      this.formInfo = {
        sex: '男',
        card_type: '1',
        state: queryData.state || '1',
        isfollow: '0',
        hot: '0',
        referral: '0',
        illness_state: '5',
        // inout_state: '1',
        supervise_start: '1',
        nucleic_acid: '0',
        is_have_healthcard: '1',
        arrive_address_type: queryData.arrive_address_type || '3'
      }
      this.getCity(null, 'provinceList', false)
      this.getDownAddress(0, 1, false)
    }
  }
}
</script>

<style scoped>
  .title-style {
    padding: 8px 12px;
    background-color: #ecf8ff;
    border-radius: 4px;
    border-left: 5px solid #50bfff;
    margin: 15px 0;
    font-size: 16px;
    width: 100%;
  }
  .table-mr5 {
    margin-right: 5px;
  }
  .add-btn {
    float: right;
    font-size: 15px;
  }
  .save-btn {
    margin: 20px
  }
  .mr20 {
    margin-right: 20px;
  }
  .bench_search {
    margin-bottom: 10px;
  }
  .help-tip {
    cursor:pointer;
    color: #5cadff;
  }
  .red-star {
    font-family: SimSun;
    color: #f00;
    margin-right: 4px;
  }
</style>
